<title>直播间管理</title>
<!--当前位置开始-->
<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <script type="text/html" template lay-done="layui.data.updateMainBreadcrumb();">
        </script>
    </div>
</div>
<!--当前位置结束-->
<style>
    /* 重写样式 */
</style>
<script type="text/html" template lay-type="Post" lay-url="{{ layui.setter.apiUrl }}Api/StudioManagement/GetIndex" lay-done="layui.data.done(d);">
</script>
<div class="table-body">
    <table id="LAY-app-StudioManagement-tableBox" lay-filter="LAY-app-StudioManagement-tableBox"></table>
</div>

<script type="text/html" id="LAY-app-StudioManagement-toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="addData"><i class="layui-icon layui-icon-add-1"></i>创建直播间</button>
    </div>
</script>

<script type="text/html" id="LAY-app-StudioManagement-pagebar">
    <div class="layui-inline">
        <a class="layui-btn layui-btn-sm" lay-event="getPushUrl">获取推流地址</a>
        <a class="layui-btn layui-btn-sm" lay-event="getShareCode">获取分享二维码</a>
        <a class="layui-btn layui-btn-sm" lay-event="getSubAnchor">修改主播副号</a>
        <a class="layui-btn layui-btn-sm" lay-event="addSubAnchor">添加主播副号</a>
    </div>
</script>

<script type="text/html" id="LAY-app-StudioManagement-tableBox-bar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" data-dropdown="#StudioManagementTbDelDrop{{d.LAY_NUM}}" no-shade="true">删除</a>
    <div class="dropdown-menu-nav dropdown-popconfirm dropdown-top-right layui-hide" id="StudioManagementTbDelDrop{{d.LAY_NUM}}"
         style="max-width: 200px;white-space: normal;min-width: auto;margin-left: 10px;">
        <div class="dropdown-anchor"></div>
        <div class="dropdown-popconfirm-title">
            <i class="layui-icon layui-icon-help"></i>
            确定要删除吗？
        </div>
        <div class="dropdown-popconfirm-btn">
            <a class="layui-btn layui-btn-primary cursor" btn-cancel>取消</a>
            <a class="layui-btn layui-btn-normal cursor" lay-event="del">确定</a>
        </div>
    </div>


</script>

<script>
    var indexData;
    var debug = layui.setter.debug;
    layui.data.done = function (d) {
        //开启调试情况下获取接口赋值数据
        if (debug) { console.log(d); }

        indexData = d.data;
        layui.use(['index', 'table', 'laydate', 'util', 'coredropdown', 'coreHelper'],
            function () {
                var $ = layui.$
                    , admin = layui.admin
                    , table = layui.table
                    , form = layui.form
                    , laydate = layui.laydate
                    , setter = layui.setter
                    , coreHelper = layui.coreHelper
                    , util = layui.util
                    , view = layui.view;

                //重载form
                form.render();
                var searchwhere;
                //监听搜索
                form.on('submit(LAY-app-StudioManagement-search)',
                    function (data) {
                        var field = data.field;
                        searchwhere = field;
                        //执行重载
                        table.reloadData('LAY-app-StudioManagement-tableBox', { where: field });
                    });
                //数据绑定
                table.render({
                    elem: '#LAY-app-StudioManagement-tableBox',
                    url: layui.setter.apiUrl + 'Api/StudioManagement/GetLiveInfo',
                    contentType: 'application/json',
                    dataType: 'json',
                    method: 'POST',
                    toolbar: '#LAY-app-StudioManagement-toolbar',
                    pagebar: '#LAY-app-StudioManagement-pagebar',
                    className: 'pagebarbox',
                    defaultToolbar: ['filter', 'print', 'exports'],
                    height: 'full-127',//面包屑142px,搜索框4行172,3行137,2行102,1行67
                    page: true,
                    limit: 30,
                    limits: [10, 15, 20, 25, 30, 50, 100, 200],
                    text: { none: '暂无相关数据' },
                    cols: [
                        [
                            { type: "radio", fixed: "left" },
                            { field: 'roomid', title: '直播间编号', width: 80, sort: false },
                            { field: 'name', title: '直播间名称', sort: false, width: 105 },

                            {
                                field: 'start_time', title: '直播间开始时间', sort: false, width: 135, templet: function (data) {
                                    if (data.end_time) {
                                        return layui.util.toDateString(data.start_time + '000', 'yyyy-MM-dd HH:mm:ss')
                                    } else {
                                        return '';
                                    }
                                }
                            },
                            //{ field: 'end_time', title: '结束时间', sort: false, width: 105 },
                            {
                                field: 'end_time', title: '直播计划结束时间', sort: false, width: 135, templet: function (data) {
                                    if (data.end_time) {
                                        return layui.util.toDateString(data.end_time + '000', 'yyyy-MM-dd HH:mm:ss')
                                    } else {
                                        return '';
                                    }
                                }
                            },
                            { field: 'anchor_name', title: '主播名', sort: false, width: 105 },
                            {
                                field: 'cover_img', title: '背景图', sort: false,
                                templet: function (d) {
                                    if (d.cover_img) {
                                        return '<a href="javascript:void(0);" onclick=layui.coreHelper.viewImage("' + d.cover_img + '")><image style="max-width:28px;max-height:28px;" src="' + d.cover_img + '" /></a>';
                                    } else {
                                        return '<a href="javascript:void(0);" onclick=layui.coreHelper.viewImage("' + setter.noImagePicUrl + '")><image style="max-width:30px;max-height:30px;" src="' + setter.noImagePicUrl + '" /></a>';
                                    }
                                }, width: 60
                            },
                            {
                                field: 'feeds_img', title: '官方收录封面', sort: false,
                                templet: function (d) {
                                    if (d.feeds_img) {
                                        return '<a href="javascript:void(0);" onclick=layui.coreHelper.viewImage("' + d.feeds_img + '")><image style="max-width:28px;max-height:28px;" src="' + d.feeds_img + '" /></a>';
                                    } else {
                                        return '<a href="javascript:void(0);" onclick=layui.coreHelper.viewImage("' + setter.noImagePicUrl + '")><image style="max-width:30px;max-height:30px;" src="' + setter.noImagePicUrl + '" /></a>';
                                    }
                                }, width: 100
                            },
                            {
                                field: 'share_img', title: '分享图', sort: false,
                                templet: function (d) {
                                    if (d.share_img) {
                                        return '<a href="javascript:void(0);" onclick=layui.coreHelper.viewImage("' + d.share_img + '")><image style="max-width:28px;max-height:28px;" src="' + d.share_img + '" /></a>';
                                    } else {
                                        return '<a href="javascript:void(0);" onclick=layui.coreHelper.viewImage("' + setter.noImagePicUrl + '")><image style="max-width:30px;max-height:30px;" src="' + setter.noImagePicUrl + '" /></a>';
                                    }
                                }, width: 60
                            },
                            { field: 'close_comment', title: '是否开启评论', width: 95, templet: '#switch_close_comment', sort: false, unresize: true },
                            { field: 'close_goods', title: '是否开启商品', width: 95, templet: '#switch_close_goods', sort: false, unresize: true },
                            { field: 'close_kf', title: '是否开启客服', width: 95, templet: '#switch_close_kf', sort: false, unresize: true },
                            { field: 'close_like', title: '是否开启点赞', width: 95, templet: '#switch_close_like', sort: false, unresize: true },
                            { field: 'close_replay', title: '是否开启回放', width: 95, templet: '#switch_close_replay', sort: false, unresize: true },
                            { field: 'is_feeds_public', title: '是否官方收录', width: 95, templet: '#switch_is_feeds_public', sort: false, unresize: true },
                            {
                                field: 'live_status', title: '直播间状态', sort: false, width: 80, templet: function (data) {
                                    for (var i = 0; i < d.data.liveStatus.length; i++) {
                                        if (d.data.liveStatus[i].value == data.live_status) {
                                            return d.data.liveStatus[i].description;
                                        }
                                    }
                                    return "";
                                }
                            },
                            {
                                field: 'live_type', title: '直播类型', sort: false, width: 80, templet: function (data) {
                                    for (var i = 0; i < d.data.liveType.length; i++) {
                                        if (d.data.liveType[i].value == data.live_type) {
                                            return d.data.liveType[i].title;
                                        }
                                    }
                                    return "";
                                }
                            },
                            //{ field: 'isDefault', title: '是否默认等级', width: 95, templet: '#switch_isDefault', sort: false, unresize: true },

                            //{ field: 'description', title: '等级说明', sort: false },
                            { align: 'center', title: '操作', fixed: 'right', toolbar: '#LAY-app-StudioManagement-tableBox-bar' }
                        ]
                    ]
                });
                //监听排序事件
                table.on('sort(LAY-app-StudioManagement-tableBox)', function (obj) {
                    table.reloadData('LAY-app-StudioManagement-tableBox', {
                        initSort: obj, //记录初始排序，如果不设的话，将无法标记表头的排序状态。
                        where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                            orderField: obj.field, //排序字段
                            orderDirection: obj.type //排序方式
                        }
                    });
                });
                //头工具栏事件
                table.on('toolbar(LAY-app-StudioManagement-tableBox)', function (obj) {
                    var checkStatus = table.checkStatus(obj.config.id);
                    switch (obj.event) {
                        case 'addData':
                            doCreate();
                            break;
                    };
                });
                //头工具栏事件
                table.on('pagebar(LAY-app-StudioManagement-tableBox)', function (obj) {
                    console.log(obj);
                    var checkStatus = table.checkStatus(obj.config.id);
                    switch (obj.event) {
                        case 'getPushUrl':
                            doGetPushUrl(checkStatus);
                            break;
                        case 'getShareCode':
                            doGetShareCode(checkStatus);
                            break;
                        case 'getSubAnchor':
                            doGetSubAnchor(checkStatus);
                            break;
                        case 'addSubAnchor':
                            doAddSubAnchor(checkStatus);
                            break;
                    };
                });
                //监听工具条
                table.on('tool(LAY-app-StudioManagement-tableBox)',
                    function (obj) {

                        var data = obj.data;
                        console.log(data);

                        if (obj.event === 'del') {
                            doDelete(obj);
                        } else if (obj.event === 'edit') {
                            doEdit(obj)
                        }
                    });
                //执行创建操作
                function doCreate() {
                    coreHelper.Post("Api/StudioManagement/GetCreate", null, function (e) {
                        if (e.code === 0) {
                            admin.popup({
                                shadeClose: false,
                                title: '创建数据',
                                area: ['1000px', '90%'],
                                id: 'LAY-popup-StudioManagement-create',
                                success: function (layero, index) {
                                    view(this.id).render('wechat/livebroadcast/studiomanagement/create', { data: e.data }).done(function () {
                                        //监听提交
                                        form.on('submit(LAY-app-StudioManagement-createForm-submit)',
                                            function (data) {
                                                var field = data.field; //获取提交的字段

                                                field.isFeedsPublic = field.isFeedsPublic == '1';
                                                field.closeLike = field.closeLike == '1';
                                                field.closeGoods = field.closeGoods == '1';
                                                field.closeComment = field.closeComment == '1';
                                                field.closeReplay = field.closeReplay == '1';
                                                field.closeShare = field.closeShare == '1';
                                                field.closeKf = field.closeKf == '1';

                                                field.startTime = new Date(field.startTime).valueOf() / 1000;
                                                field.endTime = new Date(field.endTime).valueOf() / 1000;


                                                if (debug) { console.log(field); } //开启调试返回数据
                                                //提交 Ajax 成功后，关闭当前弹层并重载表格
                                                coreHelper.Post("Api/StudioManagement/DoCreate", field, function (e) {
                                                    console.log(e)
                                                    if (e.code === 0) {
                                                        layui.table.reloadData('LAY-app-StudioManagement-tableBox'); //重载表格
                                                        layer.close(index); //再执行关闭
                                                        layer.msg(e.msg);
                                                    } else {
                                                        layer.msg(e.msg);
                                                    }
                                                });
                                            });
                                    });
                                    // 禁止弹窗出现滚动条
                                    /*$(layero).children('.layui-layer-content').css('overflow', 'visible');*/
                                }
                                , btn: ['确定', '取消']
                                , yes: function (index, layero) {
                                    layero.contents().find("#LAY-app-StudioManagement-createForm-submit").click();
                                }
                            });
                        } else {
                            layer.msg(e.msg);
                        }
                    });
                }
                //执行编辑操作
                function doEdit(obj) {
                    coreHelper.Post("Api/StudioManagement/GetEdit", obj.data, function (e) {
                        if (e.code === 0) {
                            admin.popup({
                                shadeClose: false,
                                title: '编辑数据',
                                area: ['1000px', '90%'],
                                id: 'LAY-popup-StudioManagement-edit',
                                success: function (layero, index) {
                                    view(this.id).render('wechat/livebroadcast/studiomanagement/edit', { data: e.data }).done(function () {
                                        //监听提交
                                        form.on('submit(LAY-app-StudioManagement-editForm-submit)',
                                            function (data) {
                                                var field = data.field; //获取提交的字段

                                                field.isFeedsPublic = field.isFeedsPublic == '1';
                                                field.closeLike = field.closeLike == '1';
                                                field.closeGoods = field.closeGoods == '1';
                                                field.closeComment = field.closeComment == '1';
                                                field.closeReplay = field.closeReplay == '1';
                                                field.closeShare = field.closeShare == '1';
                                                field.closeKf = field.closeKf == '1';

                                                field.startTime = new Date(field.startTime).valueOf() / 1000;
                                                field.endTime = new Date(field.endTime).valueOf() / 1000;

                                                if (debug) { console.log(field); } //开启调试返回数据
                                                //提交 Ajax 成功后，关闭当前弹层并重载表格
                                                coreHelper.Post("Api/StudioManagement/DoEdit", field, function (e) {
                                                    console.log(e)
                                                    if (e.code === 0) {
                                                        layui.table.reloadData('LAY-app-StudioManagement-tableBox'); //重载表格
                                                        layer.close(index); //再执行关闭
                                                        layer.msg(e.msg);
                                                    } else {
                                                        layer.msg(e.msg);
                                                    }
                                                });
                                            });
                                    })
                                    // 禁止弹窗出现滚动条
                                    //$(layero).children('.layui-layer-content').css('overflow', 'visible');
                                }
                                , btn: ['确定', '取消']
                                , yes: function (index, layero) {
                                    layero.contents().find("#LAY-app-StudioManagement-editForm-submit").click();
                                }
                            });
                        } else {
                            layer.msg(e.msg);
                        }
                    });
                }
                //获取推流地址
                function doGetPushUrl(obj) {
                    var checkData = obj.data;
                    if (checkData.length === 0) {
                        return layer.msg('请选择数据行');
                    }
                    var id = checkData[0].roomid
                    coreHelper.Post("Api/StudioManagement/GetPushUrl", { id: id }, function (e) {
                        if (e.code === 0) {
                            admin.popup({
                                shadeClose: false,
                                title: '获取推流地址',
                                area: ['1000px', '300px'],
                                id: 'LAY-popup-StudioManagement-getPushUrl',
                                success: function (layero, index) {
                                    view(this.id).render('wechat/livebroadcast/studiomanagement/getPushUrl', { data: e.data }).done(function () {
                                        form.render();
                                    })
                                }
                            });
                        } else {
                            layer.msg(e.msg);
                        }
                    });
                }
                //获取分享二维码
                function doGetShareCode(obj) {
                    var checkData = obj.data;
                    if (checkData.length === 0) {
                        return layer.msg('请选择数据行');
                    }
                    var id = checkData[0].roomid
                    coreHelper.Post("Api/StudioManagement/GetSharedCode", { id: id }, function (e) {
                        if (e.code === 0) {
                            admin.popup({
                                shadeClose: false,
                                title: '获取推流地址',
                                area: ['1000px', '90%'],
                                id: 'LAY-popup-StudioManagement-getSharedCode',
                                success: function (layero, index) {
                                    view(this.id).render('wechat/livebroadcast/studiomanagement/getSharedCode', { data: e.data }).done(function () {
                                        form.render();
                                    })
                                }
                            });
                        } else {
                            layer.msg(e.msg);
                        }
                    });
                }
                //获取主播副号
                function doGetSubAnchor(obj) {
                    var checkData = obj.data;
                    if (checkData.length === 0) {
                        return layer.msg('请选择数据行');
                    }
                    var id = checkData[0].roomid
                    coreHelper.Post("Api/StudioManagement/GetSubAnchor", { id: id }, function (e) {
                        if (e.code === 0) {
                            admin.popup({
                                shadeClose: false,
                                title: '修改主播副号',
                                area: ['1000px', '200px'],
                                id: 'LAY-popup-StudioManagement-getSubAnchor',
                                success: function (layero, index) {
                                    view(this.id).render('wechat/livebroadcast/studiomanagement/getSubAnchor', { data: e.data }).done(function () {
                                        //监听提交
                                        form.on('submit(LAY-app-StudioManagement-getSubAnchor-submit)',
                                            function (data) {
                                                var field = data.field; //获取提交的字段

                                                if (debug) { console.log(field); } //开启调试返回数据
                                                //提交 Ajax 成功后，关闭当前弹层并重载表格
                                                coreHelper.Post("Api/StudioManagement/ModifySubAnchor", field, function (e) {
                                                    console.log(e)
                                                    if (e.code === 0) {
                                                        layui.table.reloadData('LAY-app-StudioManagement-tableBox'); //重载表格
                                                        layer.close(index); //再执行关闭
                                                        layer.msg(e.msg);
                                                    } else {
                                                        layer.msg(e.msg);
                                                    }
                                                });
                                            });
                                    })
                                }
                                , btn: ['确定', '取消']
                                , yes: function (index, layero) {
                                    layero.contents().find("#LAY-app-StudioManagement-getSubAnchor-submit").click();
                                }
                            });
                        } else {
                            layer.msg(e.msg);
                        }
                    });
                }
                //获取主播副号
                function doAddSubAnchor(obj) {
                    var checkData = obj.data;
                    if (checkData.length === 0) {
                        return layer.msg('请选择数据行');
                    }
                    var id = checkData[0].roomid
                    coreHelper.Post("Api/StudioManagement/GetSubAnchor", { id: id }, function (e) {
                        if (e.code === 0) {
                            admin.popup({
                                shadeClose: false,
                                title: '添加主播副号',
                                area: ['1000px', '200px'],
                                id: 'LAY-popup-StudioManagement-getSubAnchor',
                                success: function (layero, index) {
                                    view(this.id).render('wechat/livebroadcast/studiomanagement/addSubAnchor', { data: e.data }).done(function () {
                                        //监听提交
                                        form.on('submit(LAY-app-StudioManagement-addSubAnchor-submit)',
                                            function (data) {
                                                var field = data.field; //获取提交的字段

                                                if (debug) { console.log(field); } //开启调试返回数据
                                                //提交 Ajax 成功后，关闭当前弹层并重载表格
                                                coreHelper.Post("Api/StudioManagement/addSubAnchor", field, function (e) {
                                                    console.log(e)
                                                    if (e.code === 0) {
                                                        layui.table.reloadData('LAY-app-StudioManagement-tableBox'); //重载表格
                                                        layer.close(index); //再执行关闭
                                                        layer.msg(e.msg);
                                                    } else {
                                                        layer.msg(e.msg);
                                                    }
                                                });
                                            });
                                    })
                                }
                                , btn: ['确定', '取消']
                                , yes: function (index, layero) {
                                    layero.contents().find("#LAY-app-StudioManagement-getSubAnchor-submit").click();
                                }
                            });
                        } else {
                            layer.msg(e.msg);
                        }
                    });
                }

                //执行单个删除
                function doDelete(obj) {
                    coreHelper.Post("Api/StudioManagement/DoDelete", { id: obj.data.roomid }, function (e) {
                        if (debug) { console.log(e); } //开启调试返回数据
                        table.reloadData('LAY-app-StudioManagement-tableBox');
                        layer.msg(e.msg);
                    });
                }


                //监听 表格复选框操作

                layui.form.on('switch(switch_isDefault)', function (obj) {
                    coreHelper.Post("Api/StudioManagement/DoSetisDefault", { id: this.value, data: obj.elem.checked }, function (e) {
                        if (debug) { console.log(e); } //开启调试返回数据
                        table.reloadData('LAY-app-StudioManagement-tableBox');
                        layer.msg(e.msg);
                    });
                });

                layui.form.on('switch(switch_isAutoUpGrade)', function (obj) {
                    coreHelper.Post("Api/StudioManagement/DoSetisAutoUpGrade", { id: this.value, data: obj.elem.checked }, function (e) {
                        if (debug) { console.log(e); } //开启调试返回数据
                        table.reloadData('LAY-app-StudioManagement-tableBox');
                        layer.msg(e.msg);
                    });
                });

            });
    };
</script>

<!--设置是否关闭评论-->
<script type="text/html" id="switch_close_comment">
    <input type="checkbox" name="switch_close_comment" value="{{d.id}}" lay-skin="switch" lay-text="已开启|已关闭" lay-filter="switch_close_comment" {{ d.close_comment=="0" ? 'checked' : '' }}>
</script>

<!--设置是否关闭商品-->
<script type="text/html" id="switch_close_goods">
    <input type="checkbox" name="switch_close_goods" value="{{d.id}}" lay-skin="switch" lay-text="已开启|已关闭" lay-filter="switch_close_goods" {{ d.close_goods=="0" ? 'checked' : '' }}>
</script>

<!--设置是否关闭商品-->
<script type="text/html" id="switch_close_kf">
    <input type="checkbox" name="switch_close_kf" value="{{d.id}}" lay-skin="switch" lay-text="已开启|已关闭" lay-filter="switch_close_kf" {{ d.close_kf=="0" ? 'checked' : '' }}>
</script>

<!--设置是否关闭点赞-->
<script type="text/html" id="switch_close_like">
    <input type="checkbox" name="switch_close_like" value="{{d.id}}" lay-skin="switch" lay-text="已开启|已关闭" lay-filter="switch_close_like" {{ d.close_like=="0" ? 'checked' : '' }}>
</script>

<!--设置是否开启回放-->
<script type="text/html" id="switch_close_replay">
    <input type="checkbox" name="switch_close_replay" value="{{d.id}}" lay-skin="switch" lay-text="已开启|已关闭" lay-filter="switch_close_replay" {{ d.close_replay=="0" ? 'checked' : '' }}>
</script>


<!--设置是否开启回放-->
<script type="text/html" id="switch_is_feeds_public">
    <input type="checkbox" name="switch_is_feeds_public" value="{{d.id}}" lay-skin="switch" lay-text="已开启|已关闭" lay-filter="switch_is_feeds_public" {{ d.is_feeds_public=="1" ? 'checked' : '' }}>
</script>

